<template>
	<view>
		<view class="ecoHomeBg pL15 pR15">
			<view class="flex alg-center jst-between">
				<view class="flex alg-center">
					<view>
						<u-image :width="120" :borderRadius="20" :height="120" v-if="userInfo?.headSculpturePath"
							class="myHeader" :src="xf.getImgUrl(userInfo?.headSculpturePath)" mode=""></u-image>
						<u-image v-else :width="120" :borderRadius="20" :height="120" :src="resources.defaultHeader"
							mode=""></u-image>
					</view>
					<view class="mL15">

						<view class="flex alg-center mL5">
							<text
								class="font20 bold">{{userInfo?.nickname||userInfo?.xflinggongOddUserInfoVo?.realName}}</text>
							<!-- <text class="font15 u-6 mL5">{{userInfo?.phone}}</text> -->
							<u-image @click="xf.onlineUtils.route(`/pages/economicPage/subpackge/myInfo/index`)"
								class="mL5" :height="24" :width="24" style="margin-bottom: 4rpx;"
								:src="resources.ecoEdit" mode=""></u-image>
						</view>
						<view class="flex  mT10">
							<u-image :width="20" :height="24" :src="resources.ecoUser" mode=""></u-image>
							<text class="font13 u-6 mL5">经纪人</text>
						</view>
					</view>
				</view>
				<view class="flex alg-center">
					<u-image :width="48" :height="48" @click="showCode=true" :src="resources.ecoCode" mode=""></u-image>
					<u-image @click="xf.onlineUtils.route('/pages/common/mySet/index')" :width="48" :height="48"
						:src="resources.ecoSet" class="mL10" mode=""></u-image>
				</view>
			</view>
			<view class="ecoWallet mT15">
				<view class="flex jst-between">
					<view class="flex alg-center">
						<text class="font13 u-6">我的钱包(元) <u-icon name="eye-fill" size="30" color="#333"></u-icon></text>
						<u-icon></u-icon>
					</view>
					<view @click="xf.onlineUtils.route(`/pages/economicPage/subpackge/myWallet/index`)"
						class="font13 u-8bd">查看更多 <u-icon color="#8d8d8d" name="arrow-right"></u-icon></view>
				</view>
				<view class="font30 bold u-ecoTheme mT10">0.00</view>
				<view class="flex alg-center mT10">
					<view class="w33">
						<view class="font13 u-6">总收益</view>
						<view class="font21 u-0 bold mT5">{{ zsy }}</view>
					</view>
					<view class="w33 pL15">
						<view class="font13 u-6">今日收益</view>
						<view class="font21 u-0 bold mT5">{{ jrsy }}</view>
					</view>
					<view class="w33 flex  jst-end">
						<view>
							<view class="font13 u-6 t-right">预估今日收益</view>
							<view class="font21 u-0 bold mT5">{{ jryjsy }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="ecoHomeDown mT10 pL15 pR15 pT20 pB10">
			<view class="flex jst-between alg-center">
				<view class="flex alg-center">
					<view @click="changeTab(i)" v-for="(item,i) in tab" :key="'tab'+i" :class="current==i?'active':''"
						class="mR10 font17 u-6 ecoTab">
						<text>{{item.name}} {{item.val}}</text>
					</view>
				</view>
				<!-- <view class="font13 u-ecoTheme" @click="xf.onlineUtils.route(`/pages/common/addCompanyOrPerson/index`)">添加</view> -->
			</view>
			<view class="mT10">
				<u-search :placeholder="tab[current].placeholder" v-model="keyWord" height="80" :show-action="false"
					bg-color="#fff" shape="square" @search="search" @clear="search">
				</u-search>
			</view>
			<mescroll-uni class="lisBox tabBarLisBox" ref="mescrollRef" @init="mescrollInit" @down="downCallback"
				@up="upCallback" :down="downOption" :up="upOption" :bottombar="false" :top="730" :wxSelfTabbar="true">
				<view class="pL15 pR15 ">
					<block v-if="current==0">
						<view class="bgf radius20 pL12 pR12 pT15 pB15 mB10" v-for="(item,i) in list" :key="'c'+i"
							@click="xf.onlineUtils.route(`/pages/economicPage/subpackge/companyJobInfo/index?id=${item.id}`)">
							<view class="flex jst-between">
								<view class="flex">
									<u-image v-if="item.comProfile" :src="xf.getImgUrl(item.comProfile)" :width="90"
										:height="90" border-radius="20" mode=""></u-image>
									<u-image v-else :src="resources.defaultHeader" :width="90" :height="90"
										border-radius="20" mode=""></u-image>
									<view class="mL10">
										<view class="comName font18 bold txt-ellipsis">{{item.comName}}</view>
										<view class="u-6 font13 mT5">联系人：{{item.comContacts}}</view>
										<view class="u-6 font13 mT5">在招职位 <text
												class="u-ecoTheme">{{item.recruitingNum}}</text> 个</view>
									</view>
								</view>
								<view class="flex">
									<view @click.stop="callPhone(item.xfOddUserId)">
										<image class="imgW54" :src="resources.job.cirMessage" mode=""></image>
									</view>
									<view class="mL10" @click.stop="chatJump(item)">
										<image class=" imgW54" :src="resources.job.cirPhone" mode=""></image>
									</view>
								</view>
							</view>
							<view class="flex alg-center mT15 jst-end">
								<view class="flex alg-center w33 jst-center u-border-right"
									@click.stop="xf.onlineUtils.route(`/pages/economicPage/subpackge/editCompany/index?id=${item.id}`)">
									<image class="imgW32" :src="resources.ecoPubEdit" mode=""></image>
									<text class="font13 u-6  mL5">编辑</text>
								</view>
								<view class="flex alg-center w33 jst-center u-border-right">
									<image class="imgW32" :src="resources.ecoTj" mode=""></image>
									<text class="font13 u-6  mL5">推荐</text>
								</view>

								<view class="flex alg-center w33 jst-center" @click.stop="unBindOpt(item)">
									<image class="imgW32" :src="resources.ecoJc" mode=""></image>
									<text class="font13 u-6  mL5">解除</text>
								</view>


							</view>

						</view>

					</block>
					<block v-else>
						<view class="bgf radius20 pL12 pR12 pT15 pB15 mB10" v-for="(item,i) in list" :key="'u'+i"
							@click="xf.onlineUtils.route(`/pages/economicPage/subpackge/personJobInfo/index?id=${item.id}`)">
							<view class="flex jst-between alg-center">
								<view class="font18 bold">{{item.realName}}</view>
								<view class="flex">
									<view @click.stop="callPhone(item.id)">
										<image class="imgW54" :src="resources.job.cirMessage" mode=""></image>
									</view>
									<view class="mL10" @click.stop="chatJump(item)">
										<image class=" imgW54" :src="resources.job.cirPhone" mode=""></image>
									</view>
								</view>
							</view>
							<view class="mT5 font15">
								<text class="u-6">职位要求：</text>
								<text>{{item.expectedPositionText}}</text>
							</view>
							<view class="flex alg-center font13 mT5">
								<image class="imgW32" :src="resources.posIcon" mode=""></image>
								<text class="posTxt mL5 txt-ellipsis"
									style="width: calc(100% - 32rpx);">{{item.homeAddress}}</text>
							</view>
							<view class="flex alg-center mT15 jst-end">
								<view class="flex alg-center w33 jst-center u-border-right"
									@click.stop="xf.onlineUtils.route(`/pages/economicPage/subpackge/editUser/index?id=${item.id}`)">
									<image class="imgW32" :src="resources.ecoPubEdit" mode=""></image>
									<text class="font13 u-6  mL5">编辑</text>
								</view>
								<view class="flex alg-center w33 jst-center u-border-right">
									<image class="imgW32" :src="resources.ecoTj" mode=""></image>
									<text class="font13 u-6  mL5">推荐</text>
								</view>

								<view class="flex alg-center w33 jst-center" @click.stop="unBindOpt(item)">
									<image class="imgW32" :src="resources.ecoJc" mode=""></image>
									<text class="font13 u-6  mL5">解除</text>
								</view>


							</view>

						</view>

					</block>

				</view>
			</mescroll-uni>
		</view>
		<u-modal v-model="showCode" :show-confirm-button="false" :show-title="false" :maskCloseAble="true">
			<view class="pL15 pR15 pT15 pB15">
				<view class="t-center bold">二维码分享</view>
				<view class="flex jst-center mT25 mB25" v-if="showCode">
					<xfQrcode :width="200" :staticText="`https://jjp.cnthr.com/h5mobile?id=${userInfo.id}`"></xfQrcode>
				</view>
			</view>
		</u-modal>
		<xfTipModal ref="tipModal"></xfTipModal>
		<xfEconomicTabbar></xfEconomicTabbar>

	</view>
</template>

<script>
	import {
		getCompanyLis,
		getUserLis,
		getUserInfo,
		unBind,
		getBrokerIncome
	} from "@/api/economicInterface/user.js"
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		getPhone
	} from "@/api/userInterface/job"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				current: 0,
				showCode: false,
				tab: [{
						name: "零活管理",
						val: 0,
						placeholder: '搜索公司'
					},
					{
						name: "个人管理",
						val: 0,
						placeholder: '搜索姓名'
					}
				],
				zsy: 0, 
				jrsy: 0, 
				jryjsy: 0,
				keyWord: '',
				list: [],
				query: {
					pageNo: 1,
					pageSize: 10
				},
				downOption: {
					use: true,
					auto: false
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					empty: {
						use: true,
						icon: '/static/image/nodata.png',
						tip: "暂无数据",
						fixed: true
					},
					textNoMore: "到底啦~",
				},
				authStatusInfo: {},
				userInfo: {}

			}
		},
		async onShow() {
			this.getUserInfoOpt()
			this.getBrokerIncomeApi()
			getUserLis(this.query).then(res => {
				this.tab[1].val = res.result.total;
			})
			this.mescroll && this.mescroll.triggerDownScroll()
		},
		onUnload() {

		},
		onHide() {

		},
		methods: {
			chatJump(item) {
				let info = {
					id: this.current == 0 ? item.xfOddUserId : item.id,
					realName: this.current == 0 ? item.comName : item.realName,
					headImage:this.current == 0 ? item.comProfile : "",
					online:""
				}
				this.chatStore.addFriend(info)
			},
			unBindOpt(item) {
				let that = this;
				let name = this.current == 0 ? item.comName : item.realName;
				this.$refs.tipModal.open({
					content: `您确定解绑 ${name}吗？`,
					btnText: "解绑",
					showCancel: true,
					success: function() {
						unBind({
							id: item.id
						}).then(res => {
							if (res.success == true) {
								that.xf.onlineUtils.toast(res.message)
								setTimeout(() => {
									that.list = [];
									that.mescroll.resetUpScroll();
								}, 2000)
							}
						})
					}
				})
			},
			//tab切换
			changeTab(i) {
				this.current = i;
				this.keyWord = ""
				this.list = [];
				this.mescroll.resetUpScroll();
			},
			search() {
				this.list = [];
				this.mescroll.resetUpScroll();
			},
			getUserInfoOpt() {
				getUserInfo().then(res => {
					this.userInfo = res.result;
					let info = res.result?.xflinggongOddUserInfoVo;
					this.authStatusInfo = info;
					this.userStore.setAuthStatus(info.authStatus)
					this.userStore.setUserInfo(JSON.stringify(info))
				})
			},
			getBrokerIncomeApi() {
				getBrokerIncome({}).then(res => {
					const { result } = res
					this.zsy = result?.zsy;
					this.jrsy = result?.jrsy;
					this.jryjsy = result?.jryjsy;
				})
			},
			callPhone(id) {
				let that = this;
				getPhone({
					acquirerId: id
				}).then(res => {
					const {
						result
					} = res
					if (result.code && result.code == 201) {
						let htmlStr = `<p class="mT10">拨打电话需支付<span class="u-red">2元</span></p>`
						this.$refs.tipModal.open({
							slotHtml: htmlStr,
							btnText: "拨打",
							showCancel: true,
							success: function() {
								that.xf.jumpPayPage(`acquirerId=${id}`)
							}
						})
					} else {
						this.$refs.tipModal.open({
							content: "确认拨打电话吗？",
							btnText: "拨打",
							showCancel: true,
							success: function() {
								that.xf.callPhone({
									acquirerId: id
								})
							}
						})
					}
				})
			},
			async upCallback(page) {
				if (page.num == 1) this.list = [];
				this.query.pageNo = page.num;
				let func
				if (this.current == 0) {
					func = getCompanyLis;
					delete this.query.realName;
					this.query.comName = this.keyWord;
				} else {
					func = getUserLis;
					delete this.query.comName
					this.query.realName = this.keyWord;
				}
				func(this.query).then(res => {
					let list = res.result.records;
					this.list = this.list.concat(list);
					this.tab[this.current].val = res.result.total;
					this.mescroll.endSuccess(list.length);

				}).catch((err) => {
					this.mescroll.endByPage(0, 0);
					this.mescroll.endErr();
				})
			},
			tipOpt() {
				this.$refs.tipModal.open({
					btnText: "关闭",
					content: "该功能暂未开放！",
				})
				// xf.onlineUtils.route('pages/common/myWallet/index')
			},
			jumpJob(e) {
				uni.switchTab({
					url: "/pages/userPage/job/index"
				})
			},
			jumpUrl(url) {
				if (url == 'changeJob') {
					let userInfo = this.xf.onlineUtils.getUserInfo()
					uni.navigateToMiniProgram({
						appId: 'wxd75ddb642c290a5e',
						path: 'pages/login/login',
						envVersion: "trial",
						success(res) {
							console.log('打开成功');
						}
					});
					// changeRole({
					// 	authenticationType: 1
					// }).then(res => {
					// 	uni.switchTab({
					// 		url: "/pages/companyPage/my/index"
					// 	})
					// })


				} else {
					this.xf.onlineUtils.route(url)
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		min-height: 100%;
		background: linear-gradient(0deg, #F8FAFF, #F7F8FB);
	}
</style>
<style scoped lang="scss">
	::v-deep .xf-qrcode {
		display: flex;
		justify-content: center;
	}

	.ecoHomeBg {
		width: 750rpx;
		height: 490rpx;
		background: linear-gradient(0deg, #F8FAFF 0%, #EBFCFF 100%);
	}

	.ecoWallet {
		border: 2rpx solid #fff;
		background: linear-gradient(155deg, #F9FEFD, #F3FFFC, #EDFDF9, );
		border-radius: 30rpx;
		padding: 40rpx 30rpx;
	}

	.ecoHomeDown {
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		border: 2rpx solid #fff;
		border-bottom: 0;
	}

	.ecoTab {
		&.active {
			font-size: 40rpx !important;
			font-weight: bold;
			color: #333;
		}
	}
	.comName{
		width: 300rpx;
	}
</style>